#!/bin/bash
echo '打包程序开始。'
echo '解压原始包。'
unzip -q /Users/fanrui/www/pack/packageold/longyin2.ipa  -d /Users/fanrui/www/pack/
echo '原始包解压完成。'
chmod -R 777 /Users/fanrui/www/pack/Payload
chmod 777 /Users/fanrui/www/pack/temp.entitlements
echo '配置各个配置文件。'
cp /Users/fanrui/www/pack/packageold/longyin2.mobileprovision /Users/fanrui/www/pack/Payload//embedded.mobileprovision


/usr/libexec/plistbuddy -c 'Set :CFBundleIdentifier ""' /Users/fanrui/www/pack/Payload//Info.plist
/usr/libexec/plistbuddy -c 'Add :CerBundleID String "fac6d596c60cfb19db496862e2f6daa1|"' /Users/fanrui/www/pack/Payload//Info.plist
/usr/libexec/plistbuddy -c 'Set :application-identifier "."' /Users/fanrui/www/pack/temp.entitlements
/usr/libexec/plistbuddy -c 'Set :com.apple.developer.team-identifier ""' /Users/fanrui/www/pack/temp.entitlements
/usr/libexec/plistbuddy -c 'Set :keychain-access-groups:0 ".*"' /Users/fanrui/www/pack/temp.entitlements
echo '开始签名'
/usr/bin/codesign --preserve-metadata=identifier,entitlements -f -s "iPhone Distribution: " --identifier "" --entitlements "/Users/fanrui/www/pack/temp.entitlements" /Users/fanrui/www/pack/Payload//
echo '开始打包'
zip -r -q /Users/fanrui/www/pack/temp.ipa /Users/fanrui/www/pack/Payload/
mv /Users/fanrui/www/pack/temp.ipa /Users/fanrui/www/pack/package/longyin2.ipa
rm -rf /Users/fanrui/www/pack/Payload